home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************************************************
- * lpr hostname printername file
- * currently only supports sending files to a printer daemon
- *
- * \1 restart remote printer \1printer\n
- * \2 send files to queue \2printer\n \3size file is datafile \2size file is controlfile \1 reset
- * \3 list queue \3printer\n number of requests or users then read from tcp connection
- * \4 list queue
- * \5 remove job from queue only local
- *******************************************************************************************************************/
-
- /************************/
- /**CHANGE HERE**/
- /************************/
- myhostname = 'zaturn'
- username = 'utzinger'
- /************************/
-
- options failat 10
-
- signal on halt
- signal on ioerr
- signal on break_c
-
- if arg() < 1 | arg(1) = '?' then call usage
-
- parse arg Hostname PrI InFiles
- parse var InFiles file InFiles
-
- say 'Printing file ' || file || ' on ' || Hostname || ' printer ' || PrI
-
- /* Open printer tcp connection and file to send */
-
- If ~Open(pr, 'TCP:' || Hostname || '/printer', 'W') Then Do; Say '*** Service not present'; Exit 10; End
- If ~Open(fl, file, 'R') Then Do; Say '*** Cannot open file'; Exit 10; End
-
- /* Init remote printer daemon to accept files */
-
- writeln(pr,d2c(2) || PrI)
- chr=readch(pr,1)
- if chr ~= d2c(0) then Do; Say '*** Unknown remote printer or no authentification: ' || c2b(chr); Exit 10; End
-
- /* produce authentic part of file name */
- num=right(time(s),3)
-
- /* send data file */
-
- size=seek(fl,0,'END')
- say 'Size Data: ' || size || ' bytes'
- nr = seek(fl,0,'BEGIN')
- writeln(pr,d2c(3) || size || ' dfA' || num || myhostname)
- chr=readch(pr,1)
- if chr ~= d2c(0) then Do; Say '*** Not enough space to print data file on remote host: ' || c2b(chr) ; Exit 10; End
- thisline=readch(fl,65535)
- do until eof(fl)
- call writech(pr,thisline)
- thisline=readch(fl,65535)
- end
- writech(pr,d2c(0))
- chr=readch(pr,1)
- if chr ~= d2c(0) then Do; Say '*** Remote host did not receive the data file correctly: ' || c2b(chr); Exit 10; End
-
- /* send control file */
-
- csize=2*length(file) + 68
- say 'Size Control: ' || csize || 'bytes'
- writeln(pr,d2c(2) || csize || ' cfA' || num || myhostname)
- chr=readch(pr,1)
- if chr ~= d2c(0) then Do; Say '*** Not enough space to print control file on remote host: ' || c2b(chr); Exit 10; End
- writeln(pr,'H' || myhostname)
- writeln(pr,'P' || username)
- writeln(pr,'J' || file)
- writeln(pr,'C' || myhostname)
- writeln(pr,'L' || username)
- writeln(pr,'fdfA' || num || myhostname)
- writeln(pr,'UdfA' || num || myhostname)
- writeln(pr,'N' || file)
- writech(pr,d2c(0))
- chr=readch(pr,1)
- if chr ~= d2c(0) then Do; Say '*** Remote host did not receive the control file correctly: ' || c2b(chr); Exit 10; End
-
- call close fl; call close pr
- say 'File printed'
- exit 0
-
- /* ----------------------------------------------------------------------- */
- /* Error Handling */
- halt:
- oerr:
- reak_c:
- exit 10
-
- /* ----------------------------------------------------------------------- */
- usage:
- say "Usage: lpr hostname printername filename"
- say
- exit 0
-